<template>
	<view class="operating-networkd-list">
		<!-- <nav-bar title="运营网点列表" :showLeftIcon="true" :leftSlot="false"></nav-bar> -->
		<view class="title" id="title">
			<text>{{companyInfo.name}}</text>
		</view>
		<scroll-view scroll-y="true" :style="{ 'height': scrollHeight + 'px'}"  @scrolltolower="loadMore">
			<view class="content-box">
				<view v-for="item,index in pointList" class="item-list" :key="index" @click="clickEtails(item)">
					<text>{{item.networkPointsName}}</text>
					<view>
						<text>联系人：{{item.businessLeaderName}}</text>
						<text>联系电话：{{item.businessLeaderPhone}}</text>
					</view>
				</view>
			</view>
			<view>
				<view class="loading" v-if="!isAllData">
				  正在加载，请稍候
				  <uni-icons type="spinner-cycle" size="16" style="margin-left: 4px;"></uni-icons>
				</view>
				<view class="all-data" v-else>已加载全部数据~</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import {
		baseIconUrl,
		baseImgUrl
	} from '@/config'
	import settleIn from '@/api/settleIn.js'
	export default {
		name: 'Store',
		components: {},
		data() {
			return {
				loadingHeight: '',
				scrollHeight: '',
				companyInfo: {
					name: '',
					id: ''
				},
				pageInfo: {
					pageSize: 10,
					pageNum: 1,
					total: 0
				},
				positionEvent: {},
				pointList: [],
				isAllData: false,
				isRequestSuccess: false,
			}
		},

		async onLoad(e) {
			this.companyInfo.name = e && e.companyName;
			this.companyInfo.id = e && e.companyId;
			let positionEvent = uni.getStorageSync("positionEvent");
			if(positionEvent && positionEvent != "{}") {
				this.positionEvent = JSON.parse(positionEvent)
			} 
			this.getPointList();
		},
		async onShow() {

		},
		mounted() {
			const systemInfo = uni.getSystemInfoSync();
			this.scrollHeight = systemInfo.windowHeight;
			const query = uni.createSelectorQuery().in(this);
			query.select('#title').boundingClientRect(data => {
				if (data) {
					this.$nextTick(() => {
						this.scrollHeight = this.scrollHeight - data.height;
					})
				}
			}).exec();
		},
		methods: {
			clickEtails(item){
				uni.navigateTo({
					url: `/subPages/settleIn/networkDetails?pointId=${item.id}&pointName=${item.networkPointsName}`
				});
			},
			// 获取网点
			async getPointList(id) {
				this.isAllData = false;
				let res = await settleIn.getPointList({
					companyId: this.companyInfo.id, 
					pageSize: this.pageInfo.pageSize,
					pageNum: this.pageInfo.pageNum
				});
				this.pointList.push(...res.rows);
				let {pageNum, pageSize, total} = this.pageInfo;
				if(pageNum  >= total / pageSize) {
					this.isAllData = true;
				}
			},
			loadMore() {
				conso.log("加载更多")
				let {pageNum, pageSize, total} = this.pageInfo;
				if(pageNum  >= total / pageSize) {
					this.isAllData = true;
					return;
				}
				this.$set(this.pageInfo, 'pageNum', pageNum+1);
				this.getPointList();
			},
			onRefresh() {
				uni.stopPullDownRefresh();
			},
		}
	}
</script>
<style lang="scss" scoped>
	.loading,
	  .all-data {
	    display: flex;
	    justify-content: center;
	    align-items: center;
	    color: #999;
		padding: 15rpx 0;
	  }
	.operating-networkd-list {
		background: #ffffff;

		.title {
			padding: 20rpx 30rpx;
			background: #e8f2ff;

			text {
				font-family: "PingFang SC";
				font-size: 30rpx;
				font-style: normal;
				font-weight: 500;
				line-height: 40rpx;
				opacity: 0.9;
			}
		}

		.content-box {
			padding: 30rpx;
			padding-top: 0;
			background: #ffffff;
			.item-list {
				>text {
					display: block;
					font-family: "PingFang SC";
					line-height: 40rpx;
					opacity: 0.9;
					padding-top: 40rpx;
					margin-bottom: 20rpx;
					font-size: 28rpx;
					font-weight: 400;
				}

				view {
					display: flex;
					justify-content: space-between;

					>text {
						font-family: "PingFang SC";
						line-height: 40rpx;
						opacity: 0.5;
						font-size: 24rpx;
					}
				}
			}
		}
	}
</style>